package com.honey.solr;

import java.io.File;

import org.java.plugin.Plugin;

import com.honey.core.Extension;
import com.honey.core.compiler.CompilationDescriptor;
import com.honey.core.compiler.CompilationType;
import com.honey.core.compiler.ContentType;
import com.honey.core.compiler.StorageType;
import com.honey.core.dbmapping.introspect.IntrospectSchema;
import com.honey.core.dbmapping.introspect.IntrospectSchemaColumn;
import com.honey.core.generator.CodeCompilation;
import com.honey.solr.schema.SolrSchema;

public class SolrSchemaExtension  extends Extension<Plugin> implements CodeCompilation {
	public SolrPlugin solrPlugin = null;
	public SolrSchemaExtension(Plugin belongPlugin) {
		super(belongPlugin);
		solrPlugin = (SolrPlugin)belongPlugin;
	}

	@Override
	public CompilationDescriptor[] compilation(IntrospectSchema schema, IntrospectSchemaColumn columns) {
		CompilationDescriptor[] answer = null;
		StorageType storageType = solrPlugin.getProjectEnvironmentHolder().getStorageType();
		String charset = solrPlugin.getProjectEnvironmentHolder().getCharset();
		String workespace= solrPlugin.getSolrSchemaFile();
		if( workespace != null ){
			File f = new File(workespace);
			answer =  new CompilationDescriptor[]{
				new CompilationDescriptor(
						(new SolrSchema(new SolrFactory(solrPlugin))).getDocument(), 
						f.getParent(), 
						CompilationType.XML,
						storageType,
						ContentType.XML_MYBATIS_MAPPER_CONFIGURETION, 
						charset
					),
				};
		}
		return answer; 
	}
	
	@Override
	public void clean() {
	}
}
